package com.summer.springboot.ex.std.controller;

import cn.hutool.core.util.StrUtil;
import com.summer.springboot.ex.std.enums.CustomExceptionType;
import com.summer.springboot.ex.std.exception.CustomException;
import com.summer.springboot.ex.std.service.UserService;
import com.summer.springboot.ex.std.util.JsonResult;
import com.summer.springboot.ex.std.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping
    public JsonResult getUser(String username) {
        if(StrUtil.isBlank(username)) {
            throw new CustomException(CustomExceptionType.SYSTEM_ERROR, "Controller抛出：用户名不能为空");
        }
        return JsonResult.success();
    }

    @PostMapping
    public JsonResult saveUser(@Valid UserVo userVo) {
        userService.save(userVo);
        return JsonResult.success();
    }
}
